package com.imooc;

import org.junit.Test;

import java.util.function.*;

public class MethodRefrence {

    @Test
    public void consumer() {
        Consumer<String> consumer = System.out :: println;
        consumer.accept("数据");
    }

    @Test
    public void staticLambda() {
        Consumer<Dog> consumer = Dog :: say;
        consumer.accept(new Dog("哮天犬"));
    }

    @Test
    public void funct() {
        Dog dog = new Dog("哮天犬");
        Function<Integer, Integer> function = dog :: eat;
        function.apply(2);
    }

    @Test
    public void oneArgusFunct() {
        Dog dog = new Dog("哮天犬");
        UnaryOperator<Integer> function = dog :: eat;
        function.apply(2);
    }

    @Test
    public void baseFunct() {
        Dog dog = new Dog("哮天犬");
        IntUnaryOperator function = dog :: eat;
        function.applyAsInt(2);
    }

    @Test
    public void bigFunct() {
        Dog dog = new Dog("哮天犬");
        BiFunction<Dog, Integer, Integer> eatF= Dog :: eat;
        eatF.apply(dog, 7);
    }

    @Test
    public void constru() {
        Supplier<Dog> dogSupplier = Dog :: new;
        dogSupplier.get();

        Function<String, Dog> function = Dog :: new;
        System.out.println(function.apply("旺财"));
    }


}

class Dog {

    private String name;
    private int foor = 10;

    public static void say(Dog dog) {
        System.out.println(dog + "叫了");
    }

    public int eat(Dog this, int i) {
        this.foor -= i;
        System.out.println("还剩" + this.foor + "斤");
        return this.foor;
    }

    public Dog() {
    }

    public Dog(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }
}
